package svc

import (
	"MBTI/api/internal/config"
	"MBTI/common"
	"MBTI/rpc/admin/admin"
	"MBTI/rpc/login/login"
	"MBTI/rpc/student/student"

	"github.com/go-redis/redis"
	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config     config.Config
	LoginRpc   login.Login
	StudentRpc student.Student
	AdminRpc   admin.Admin
	Redis      *redis.Client
}

func NewServiceContext(c config.Config) *ServiceContext {
	redis := common.NewRedis(c.Redis.Host, c.Redis.Password, c.Redis.Db)
	return &ServiceContext{
		Config:     c,
		LoginRpc:   login.NewLogin(zrpc.MustNewClient(c.LoginRpc)),
		StudentRpc: student.NewStudent(zrpc.MustNewClient(c.StudentRpc)),
		AdminRpc:   admin.NewAdmin(zrpc.MustNewClient(c.AdminRpc)),
		Redis:      redis,
	}
}
